package com.study.example;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Random;

@Component

public class Receiver {

    @RabbitListener(queues="queue")    //监听器监听指定的Queue
    public void processC(String str) throws InterruptedException {
        System.out.println("processC receive:"+str);
        Thread.sleep(2000);
        System.out.println("processC execute success");
    }

    @RabbitListener(queues="queue")    //监听器监听指定的Queue
    public void processA(String str) throws InterruptedException {
        System.out.println("processA receive:"+str);
        Thread.sleep(3000);
        System.out.println("processA execute success");
    }

    @RabbitListener(queues="queue")    //监听器监听指定的Queue
    public void processB(String str,Channel channel) throws InterruptedException {
        System.out.println("processB receive:"+str);
        Thread.sleep(5000);
        boolean b = new Random().nextBoolean();
        if (b)
        System.out.println("processB execute success");
    }



}
